<template>
  <div>
    <p style="font-size: 14px;margin-bottom: 15px;">标题:</p>
    <el-input size="mini" :style="{width: '100%',marginBottom:'30px'}" v-model="viewModel.title" placeholder="请输入标题标题">
    </el-input>
    <el-checkbox size="mini" :style="{width: '100%',marginBottom:'30px'}" v-model="viewModel.required"> 必填</el-checkbox>
    <p style="font-size: 14px;margin-bottom: 15px;">选项配置:</p>
    <draggable v-model="viewModel.optionList" v-bind="dragOption"
      style="height: 100%;width: 100%;">
      <div v-for="(item,index) in viewModel.optionList" :key="index">
        <el-row :gutter="12" style="margin-bottom: 10px;display: flex;align-items: center;">
          <el-col :span="12">
            <el-input size="mini" v-model="item.label">
            </el-input>
          </el-col>
          <el-col :span="3" :offset="1">
            <i class="el-icon-circle-plus-outline" @click="addSessionsNum(index)"></i>
          </el-col>
          <el-col :span="3">
            <i class="el-icon-remove-outline" @click="cutSessionsNum(index)"></i>
          </el-col>
          <el-col :span="3">
            <i class="el-icon-rank drag-handle"></i>
          </el-col>
        </el-row>
      </div>
    </draggable>
  </div>
</template>

<script>
  import {
    OptionItem
  } from "@/fields/config";
  import draggable from 'vuedraggable'
  export default {
    name: "checkboxConfig",
    components: {
      draggable
    },
    props: ["currCfg"],
    data() {
      return {
        dragOption: {
          sort: true,
          ghostClass: "ghost",
          handle:'.drag-handle',
          animation:300,
        },
      };
    },
    computed: {
      viewModel() {
        return this.currCfg.config;
      }
    },
    methods: {
      addSessionsNum(index) { //增加选项
        var that = this
        that.viewModel.optionList.splice(index + 1, 0, new OptionItem("选项" + (that.viewModel.optionList.length)))
        // that.viewModel.optionList.push(new OptionItem("选项" + (that.viewModel.optionList.length+1)))
      },

      cutSessionsNum(index) { //减少选项
        var that = this
        that.viewModel.optionList.splice(index, 1)

      },
    },
    mounted() {

    }
  }
</script>,
<style scoped>
  .el-icon-circle-plus-outline:hover,.el-icon-remove-outline:hover,.el-icon-rank:hover{
    color: #409EFF;
    cursor: pointer;
  }
</style>
